package com.example.leepong.Game.Utils;

/**
 * Created by Ichigo on 28/02/14.
 */

public class Stopwatch {

    private long startTime = 0;
    private long stopTime = 0;
    private boolean running = false;


    public void Start() {
        if (this.stopTime > 0 && this.startTime > 0) {
            this.startTime = System.currentTimeMillis() - (this.stopTime - this.startTime);
            this.stopTime = 0;
        } else
            this.startTime = System.currentTimeMillis();

        this.running = true;
    }

    public void Restart() {
        this.startTime = System.currentTimeMillis();
        this.running = true;
    }

    public void Pause() {
        this.stopTime = System.currentTimeMillis();
        this.running = false;
    }

    //elaspsed time in milliseconds
    public long getElapsedMilliseconds() {
        long elapsed;
        if (running) {
            return (System.currentTimeMillis() - startTime);
        } else {
            elapsed = (stopTime - startTime);
        }
        return elapsed;
    }
}

